package action.contract;

import java.util.List;

import javax.mail.Session;

import model.company.Companybasic;
import model.company.Companycontact;
import model.company.Companypledger;
import model.company.Companytopmanager;
import model.credit.Applycustomrelation;
import model.personal.Personalbasic;

import service.app.CreatKeyService;
import service.contract.ContractService;
import util.Sessions;
import util.Time;

import core.action.BaseAction;
import exception.Exceptions;

public class ContractRelationListAction extends BaseAction{
	private ContractService contractService;
	private String title;
	private String type;
	private Integer applyid;//jsp界面传过来的申请编号
	private String contracttype;
	private String contractY;
	private Integer contractnumber;
	private Integer relationid;
	private String customname;
	private Integer codetype;
	private String customcode;
	private String address;
	private String phone;
	private String fax;
	private String nameofspouse;
	private Companypledger things;
	private String loanname;
	private String Legalrepresentative;
	private CreatKeyService creatKeyService;
	private String position;
	private List<?> codetypelist;
	private List<?> relationlist;
	private String F;
	
	public String execute(){
		return "success";
	}
	
	public String getMortgageList(){
		Integer creditid=(Integer)Sessions.get("creditid");
		relationlist=contractService.showRelation(creditid,1);
		title="抵押";
		type="2";
		return "success";
	}
	
	public String getPledgeList(){
		Integer creditid=(Integer)Sessions.get("creditid");
		relationlist=contractService.showRelation(creditid,2);
		title="质押";
		type="3";
		return "success";
	}
		
	public String createRelationDetail() throws Exceptions{
		Sessions.set("relationid", relationid);
		Applycustomrelation applyrelation=contractService.getapplyrelation("id",relationid);
		Sessions.set("creditid", applyrelation.getApplyid());
		contractY=Time.Timestamp2YearString();
		if(applyrelation.getClienttype().equals(1)){
			loanname=contractService.get_personalbasic(applyrelation.getClientid()).getName();
		}else{
			loanname=contractService.get_companybasic(applyrelation.getClientid()).getName();
		}
		if(applyrelation.getRelationpeopletype().equals(2)){
		Companybasic company=contractService.get_companybasic(applyrelation.getRelationpeopleid());
		customname=company.getName();
		codetypelist=contractService.getIdtypeList();
		codetype=company.getRegcertificates();//证件类型
		customcode=company.getRegcertificatesnumber().toString();
		address=company.getRegaddress();
		Companycontact contact=contractService.get_companycontact(applyrelation.getRelationpeopleid());
		phone=contact.getTelephone();
		fax=contact.getFax();
		Companytopmanager topmanager=contractService.get_topmanager("cid="+company.getId()+"and category=1");
		setLegalrepresentative(topmanager.getName());
		setPosition("法人代表");
		things=contractService.get_customthings(applyrelation.getThingsid());
		F="2";
		}else{
			Personalbasic personal=contractService.get_personalbasic(applyrelation.getRelationpeopleid());
			customname=personal.getName();
			codetypelist=contractService.getIdtypeList();
			codetype=personal.getCertificatetype();//证件类型
			customcode=personal.getCertificatenumber();
			address=personal.getCurrentresidentialaddress();
			phone=personal.getHomephone();
			fax="";
			setLegalrepresentative("");
			setPosition("");
			nameofspouse=personal.getNameofspouse();
			things=contractService.get_customthings(applyrelation.getThingsid());
			F="1";
		}
		if(contracttype.equals("2")){
			contractnumber=creatKeyService.creatKeyOnly(332);
		successResultValue="../contract/contractMortgage";
		}else{
			contractnumber=creatKeyService.creatKeyOnly(342);
		successResultValue="../contract/contractPledge";
		}
		return "function";
	}
	
	//--------------GET/SET-----------//

	public ContractService getContractService() {
		return contractService;
	}

	public void setContractService(ContractService contractService) {
		this.contractService = contractService;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getContractY() {
		return contractY;
	}

	public void setContractY(String contractY) {
		this.contractY = contractY;
	}

	public Integer getRelationid() {
		return relationid;
	}

	public void setRelationid(Integer relationid) {
		this.relationid = relationid;
	}

	public String getCustomname() {
		return customname;
	}

	public void setCustomname(String customname) {
		this.customname = customname;
	}

	public String getCustomcode() {
		return customcode;
	}

	public void setCustomcode(String customcode) {
		this.customcode = customcode;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public Companypledger getThings() {
		return things;
	}

	public void setThings(Companypledger things) {
		this.things = things;
	}

	public String getContracttype() {
		return contracttype;
	}

	public void setContracttype(String contracttype) {
		this.contracttype = contracttype;
	}

	/*public String getLoanname() {
		return loanname;
	}

	public void setLoanname(String loanname) {
		this.loanname = loanname;
	}*/

	public String getNameofspouse() {
		return nameofspouse;
	}

	public void setNameofspouse(String nameofspouse) {
		this.nameofspouse = nameofspouse;
	}

	public String getLegalrepresentative() {
		return Legalrepresentative;
	}

	public void setLegalrepresentative(String legalrepresentative) {
		Legalrepresentative = legalrepresentative;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public Integer getApplyid() {
		return applyid;
	}

	public void setApplyid(Integer applyid) {
		this.applyid = applyid;
	}

	public Integer getContractnumber() {
		return contractnumber;
	}

	public void setContractnumber(Integer contractnumber) {
		this.contractnumber = contractnumber;
	}

	public CreatKeyService getCreatKeyService() {
		return creatKeyService;
	}

	public void setCreatKeyService(CreatKeyService creatKeyService) {
		this.creatKeyService = creatKeyService;
	}

	public Integer getCodetype() {
		return codetype;
	}

	public void setCodetype(Integer codetype) {
		this.codetype = codetype;
	}

	public List<?> getCodetypelist() {
		return codetypelist;
	}

	public void setCodetypelist(List<?> codetypelist) {
		this.codetypelist = codetypelist;
	}

	public String getLoanname() {
		return loanname;
	}

	public void setLoanname(String loanname) {
		this.loanname = loanname;
	}

	public String getF() {
		return F;
	}

	public void setF(String f) {
		F = f;
	}

	public List<?> getRelationlist() {
		return relationlist;
	}

	public void setRelationlist(List<?> relationlist) {
		this.relationlist =relationlist;
	} 

}
